package com.explorati.interview.interview.chapterten;

import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Date;

public class MyThread extends Thread {

	// 连接点
	private Socket socket;

	public MyThread(Socket socket) {
		this.socket = socket;
	}

	public void run() {
		OutputStream os = null;
		try {
			// 获得输出流
			os = socket.getOutputStream();
			// 创建PrintWriter对象
			PrintWriter pw = new PrintWriter(os);
			// 往输出流写出当前的时间
			pw.println("now time = " + new Date());
			pw.flush();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				os.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}

	}
}
